using System;
using System.IO;
using MonoDevelop.Ide;
using MonoDevelop.Ide.Gui;
using MonoDevelop.Ide.Codons;

namespace MonoDevelop.ResourceEditor.Gui
{
	/// <summary>Defines the Resource Editor display bindings that creates IViewContents</summary>	
	public class ResourceEditorDisplayBinding : MonoDevelop.Ide.Codons.IDisplayBinding
	{
		/// <summary>Gets the display name of the binding, to be shown when there are several options for opening a file.</summary>
		/// <value>A string contaning the display name of the binding.</value>
		public string DisplayName 
		{
			get { return "Resource Editor"; }
		}
		
		/// <summary>Determines if the display binding is able to create an IViewContent for the file given by fileName.</summary>
		/// <param name="fileName">A string contaning the fileName to be checked.</param>
		/// <returns>True, if this display binding is able to create an IViewContent for the file given by fileName. False otherwise.</returns>
		public bool CanCreateContentForFile(string fileName)
		{
			return Path.GetExtension(fileName).Equals(".RESOURCES", StringComparison.OrdinalIgnoreCase) ||
				Path.GetExtension(fileName).Equals(".RESX", StringComparison.OrdinalIgnoreCase);
		}
		
		/// <summary>Determines if the display binding is able to create an IViewContent for the MimeType given by mimeType.</summary>
		/// <param name="mimeType">A string contaning the MimeType to be checked.</param>
		/// <returns>True, if this display binding is able to create an IViewContent for the MimeType given by mimeType. False otherwise.</returns>
		public bool CanCreateContentForMimeType(string mimeType)
		{
			return true;
		}
		
		/// <summary>Creates a new IViewContent object for the file fileName</summary>
		/// <param name="fileName">A string containing the path of the file.</param>
		/// <returns>A newly created IViewContent object.</returns>
		public IViewContent CreateContentForFile(string fileName)
		{
			ResourceEditorView resourceEditor = new ResourceEditorView(); 
			resourceEditor.Load(fileName);
			return resourceEditor;
		}
		
		/// <summary>Creates a new IViewContent object for the MimeType given by mimeType</summary>
		/// <param name="mimeType">A string containing the MimeType.</param>
		/// <param name="content">A Stream containing the content to be used.</param>
		/// <returns>A newly created IViewContent object.</returns>
		public IViewContent CreateContentForMimeType(string mimeType, Stream content)
		{
			return new ResourceEditorView();
		}
	}
}
